<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateAdminRoleTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('admin_role', ['comment' => '角色', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('parent_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '上级ID'])
            ->addColumn('name', 'string', ['limit'  =>  60, 'default' => '', 'comment' => '角色名称'])
            ->addColumn('code', 'string', ['limit'  =>  60, 'default' => '', 'comment' => '标识'])
            ->addColumn('description', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '描述'])
            ->addColumn('rules', 'string', ['limit'  =>  2500, 'default' => '', 'comment' => '权限规则'])
            ->addColumn(Column::enum('status', ['normal', 'disabled'])->setDefault('normal')->setComment('状态'))
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('code', ['unique'  =>  true])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('admin_role');
        $table->drop();
    }
}
